class Solution {
public:
    void bitsum(int &n)
    {
        int sum=0;
        int k=n;
        while(k)
        {
            sum+=pow(k%10,2);            
            k/=10;                
        }
        n=sum;
    }
    bool isHappy(int n) {
        int slow=n;
        int fast=n;
        bitsum(fast);
        while(slow!=fast)
        {
            bitsum(slow);
            bitsum(fast);
            bitsum(fast);
        }
        if(slow==1)return true;
        else
        return false;
    }
};
